package com.tony.demo.ui.widgets;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.tony.demo.R;
import com.tony.demo.mvp.presenter.interfaces.IBasePresenter;
import com.tony.demo.test.swipe_coordinator.SwipeRefreshCoordinatorActivity;
import com.tony.demo.ui.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义控件页面
 */
public class UiWidgetsFragment extends BaseFragment {

    ListView listView;

    List<String> list = new ArrayList<>();

    @Override
    public IBasePresenter createPresenter() {
        return null;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData();
    }

    protected void initData() {
        listView = mView.findViewById(R.id.list_view);

        list.add("扫描动画");
        list.add("测试弹窗Activity的生命周期");
        list.add("时间、油表控件");
        list.add("运动时间");
        listView.setAdapter(new ArrayAdapter<>(mView.getContext(), android.R.layout.simple_list_item_1, list));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                onListItemClick((String) parent.getAdapter().getItem(position));
            }
        });
    }

    @Override
    protected int getViewLayout() {
        return R.layout.fragment_performance_optimize;
    }

    private void onListItemClick(String item) {
        switch (item) {
            case "扫描动画":
                startActivity(ScanningActivity.class);
                break;
            case "测试弹窗Activity的生命周期":
                //弹AlertDialog不会执行onStart(), onResume()方法, 也不会执行onPause(), onStop()方法
//                AlertDialogUtil.alert(this, "测试弹窗Activity的生命周期");

                //弹dialog不会执行onStart(), onResume()方法, 也不会执行onPause(), onStop()方法
//                RedPacketDialog.showRedPacketDialog(this);

                startActivity(SwipeRefreshCoordinatorActivity.class);
                break;
            case "时间、油表控件":
                startActivity(OilTableViewActivity.class);
                break;
            case "运动时间":
                startActivity(SportTimeActivity.class);
                break;
        }
    }

}
